/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Beans;

import Entities.TblBranch;
import Entities.TblClass;
import Entities.TblSemester;
import Entities.TblStaff;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author CuongNV
 */
@ManagedBean
@RequestScoped
public class ClassManagedBean extends TblClass {

    /** Creates a new instance of ClassManagedBean */
    public ClassManagedBean() {
    }
    private List<TblClass> all;
    private static TblClass classBean;
    private List<TblClass> allByBranchId;

    public List<TblClass> getAll() {
        try {
            return new BLL.ClassBLL().getAll();
        } catch (Exception ex) {
            Logger.getLogger(BranchManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public List<TblClass> getAllByBranchId() {
//        FacesContext context=FacesContext.getCurrentInstance();
//        HttpSession session=(HttpSession) context.getExternalContext().getSession(false);
//        TblStaff staff= (TblStaff) session.getAttribute("staff");
//        return new BLL.ClassBLL().getAllByBranchId(staff.getBranchId());
        return new BLL.ClassBLL().getAllByBranchId(1);
    }

    public String add() {
        try {
            new BLL.ClassBLL().add(this.classBean);
            return "classlist";
        } catch (Exception ex) {
            Logger.getLogger(BranchManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            return "null";
        }
    }

    public String update() {
        if (new BLL.ClassBLL().update(this.classBean)) {
            return "classlist";
        }else{
            return "null";
        }
    }

    public String delete() {
        if (new BLL.ClassBLL().delete(this.classBean)) {
            return "classlist";
        }else{
            return "null";
        }
    }

    public TblBranch branchNameById(int branchIdtag){
        return new BLL.BranchBLL().getById(branchIdtag);
    }
    
    public String semesterNameById(int semesterId){
        TblSemester objSems=new BLL.SemesterBLL().getById(semesterId);
        return objSems.getSemesterName();
    }
    public String staffNameById(int staffId) throws Exception{
        TblStaff objStaff=new BLL.StaffBLL().getById(staffId);
        return objStaff.getStaffName();
    }

    public TblClass getClassBean() {
        return classBean;
    }

    public void setClassBean(TblClass classBean) {
        this.classBean = classBean;
    }
}
